package com.chenchen.tiguan.venue.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chenchen.tiguan.common.core.domain.entity.SysUser;
import com.chenchen.tiguan.venue.domain.VenueCourt;
import com.chenchen.tiguan.venue.domain.VenueTimeSlot;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenchen.tiguan.common.annotation.Log;
import com.chenchen.tiguan.common.core.controller.BaseController;
import com.chenchen.tiguan.common.core.domain.AjaxResult;
import com.chenchen.tiguan.common.enums.BusinessType;
import com.chenchen.tiguan.venue.domain.VenueReservation;
import com.chenchen.tiguan.venue.service.IVenueReservationService;
import com.chenchen.tiguan.common.utils.poi.ExcelUtil;
import com.chenchen.tiguan.common.core.page.TableDataInfo;

/**
 * 用户预约记录Controller
 * 
 * @author chenchen
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/venue/reservation")
public class VenueReservationController extends BaseController
{
    @Autowired
    private IVenueReservationService venueReservationService;

    /**
     * 查询用户预约记录列表
     */
    @PreAuthorize("@ss.hasPermi('venue:reservation:list')")
    @GetMapping("/list")
    public TableDataInfo list(VenueReservation venueReservation,@Param("sysUserName") String sysUserName,
                              @Param("date") @JsonFormat(pattern = "yyyy-MM-dd") Date date)
    {
        SysUser sysUser = new SysUser();
        sysUser.setNickName(sysUserName);
        venueReservation.setSysUser(sysUser);

        VenueTimeSlot venueTimeSlot = new VenueTimeSlot();
        venueTimeSlot.setDate(date);
        venueReservation.setVenueTimeSlot(venueTimeSlot);
        startPage();
        List<VenueReservation> list = venueReservationService.selectVenueReservationList(venueReservation);
        return getDataTable(list);
    }

    /**
     * 导出用户预约记录列表
     */
    @PreAuthorize("@ss.hasPermi('venue:reservation:export')")
    @Log(title = "用户预约记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VenueReservation venueReservation)
    {
        List<VenueReservation> list = venueReservationService.selectVenueReservationList(venueReservation);
        ExcelUtil<VenueReservation> util = new ExcelUtil<VenueReservation>(VenueReservation.class);
        util.exportExcel(response, list, "用户预约记录数据");
    }

    /**
     * 获取用户预约记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('venue:reservation:query')")
    @GetMapping(value = "/{reservationId}")
    public AjaxResult getInfo(@PathVariable("reservationId") Long reservationId)
    {
        return success(venueReservationService.selectVenueReservationByReservationId(reservationId));
    }

    /**
     * 新增用户预约记录
     */
    @PreAuthorize("@ss.hasPermi('venue:reservation:add')")
    @Log(title = "用户预约记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VenueReservation venueReservation)
    {
        return toAjax(venueReservationService.insertVenueReservation(venueReservation));
    }

    /**
     * 修改用户预约记录
     */
    @PreAuthorize("@ss.hasPermi('venue:reservation:edit')")
    @Log(title = "用户预约记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VenueReservation venueReservation)
    {
        return toAjax(venueReservationService.updateVenueReservation(venueReservation));
    }

    /**
     * 删除用户预约记录
     */
    @PreAuthorize("@ss.hasPermi('venue:reservation:remove')")
    @Log(title = "用户预约记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reservationIds}")
    public AjaxResult remove(@PathVariable Long[] reservationIds)
    {
        return toAjax(venueReservationService.deleteVenueReservationByReservationIds(reservationIds));
    }
}
